<template>
  <div class="header">
    <div class="headerAll">
      <div class="header-left">
        <el-button size="small" class="ml10px mr-20px" plain @click="handleCollapse">
          <el-icon :size="20">
            <Menu />
          </el-icon>
        </el-button>
        <el-breadcrumb separator="/" class="crumbs">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item v-for="item in navCrumbs" :key="item.path" :to="item.path">{{ item.meta.title
            }}</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
        <div class="flex justify-between w130px ">
        <screenFull></screenFull>
        <language></language>
        <ThemeSwitch></ThemeSwitch>
        <el-dropdown>
          <span class="headPortrait mr10px">
            <img src="@/assets/img/head.jpg">
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="goPersonalCenter">个人中心</el-dropdown-item>
              <el-dropdown-item>退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>

  </div>
</template>

<script setup>
import { useStore, } from 'vuex'
import { useRoute, useRouter } from 'vue-router'
import { computed, onMounted } from 'vue';
import screenFull from './screenfull/screenFull.vue'
import language from './language/language.vue'
import ThemeSwitch from './ThemeSwitch/ThemeSwitch.vue'
const router = useRoute()   //获取路径用的
const isRouter = useRouter()  //跳转路径用的
const store = useStore()
const handleCollapse = () => {
  store.commit('updateIsCollapse')
}

// 获取路由实现面包屑导航
const navCrumbs = computed(() => {
  const routerInfo = router.matched.filter(item => item.meta && item.meta.title)
  if (routerInfo.length === 1 && routerInfo[0].path === '/home') {
    return []
  }
  return routerInfo
})

//面包屑导航
const current = computed(()=>{
  return store.state.breadcrumbNavigation
})
onMounted(()=>{
  current
})
//点击跳转到个人中心
const goPersonalCenter = ()=>{
  isRouter.push('/personalCenter')
}
</script>

<style scoped lang="scss">
.header {
  width: 100%;
  height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background-color: #333;
  padding: 0;
  .headerAll{
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .header-left {
    height: 100%;
    display: flex;
    align-items: center;
    color: white;

  }
  
}
.headPortrait img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.el-dropdown:hover {
  outline: none
}
// .el-dropdown:focus{
  
// }
.crumbs {
  :deep(span) {
    color: white !important;
  }
}
</style>